﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2017-20XX，米兔网络                                         *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间:2019年6月3日 18:58:38
 *  文件描述:简单存储一个Int值的缓存队列
 *****************************************************************************/

namespace StorageModels
{
    using System;
    using System.Collections.Generic;

    public class StorageEasyString : StorageModel
    {
        private Dictionary<StorageStringKey, string> EasyValue = new Dictionary<StorageStringKey, string>();
        private Dictionary<StorageStringKey, string> EasyKey = new Dictionary<StorageStringKey, string>();
        private List<StorageStringKey> PrepareEasyIntKey = new List<StorageStringKey>();

        public static StorageEasyString Loads()
        {
            return StorageModelSys.Instance.GetModelData<StorageEasyString>(StorageModelType.EasyString);
        }

        public override void Load()
        {
            var arr = Enum.GetValues(typeof(StorageStringKey));
            for (int i = 0; i < arr.Length; i++)
            {
                int ikey = (int)arr.GetValue(i);
                StorageStringKey tkey = (StorageStringKey)ikey;
                string key = string.Format("{0}_{1}", Key, ikey);//存档真实键
                string v = "";// GameEntry.Setting.GetString(key);//获取存档

                EasyValue.Add(tkey, v);
                EasyKey.Add(tkey, key);
            }
        }

        public void SetString(StorageStringKey skey, string v)
        {
            EasyValue[skey] = v;
            PrepareEasyIntKey.Add(skey);
            Save();
        }

        public string GetString(StorageStringKey skey)
        {
            return EasyValue[skey];
        }

        public override void Write()
        {
            base.Write();
            for (int i = 0; i < PrepareEasyIntKey.Count; i++)
            {
                StorageStringKey skey = PrepareEasyIntKey[i];
                string key = EasyKey[skey];
                string v = EasyValue[skey];
                //真实写存档
                //GameEntry.Setting.SetString(key, v);
            }
            PrepareEasyIntKey.Clear();
        }
    }
}